package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.api.RemoteStrategyService;
import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.api.domain.StrategyEs;
import cn.wolfcode.wolf2w.business.repository.StrategyEsRepository;
import cn.wolfcode.wolf2w.business.service.IStrategyEsService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyEsServiceImpl implements IStrategyEsService {
    @Autowired
    private StrategyEsRepository repository;
    @Autowired
    private RemoteStrategyService remoteStrategyService;

    @Override
    public void initStrategyEs() {
        List<Strategy> list = remoteStrategyService.list("inner").getData();
        for (Strategy strategy : list) {
            StrategyEs es = new StrategyEs();
            /**
             * 属性拷贝方法，会将同名属性从source拷贝到target
             * 参数1： source
             * 参数2： target
             * */
            BeanUtils.copyProperties(strategy, es);
            repository.save(es);
        }
    }
}
